//
//  WWMiddleView.m
//  快医
//
//  Created by 张湾湾 on 16/7/7.
//
//

#import "WWMiddleView.h"

@interface WWMiddleView()


/**中间View*/
@property (nonatomic,weak)UIView  *middleView;


@end
@implementation WWMiddleView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        //MARK: - 初始化页面
        [self setupUI];
        
        //MARK: - 约束
        [self setupConstains];
        
        
        self.rightLabel.textColor = [UIColor lightGrayColor];
        self.leftLabel.textColor = XHRColorWithRGB(119, 210, 210) ;
    }
    return self;
}

#pragma mark
#pragma mark - setupUI
- (void)setupUI{
    
    //MARK: - 中间view
    UIView * middleView = [[UIView alloc]init];
    self.middleView = middleView;
    self.middleView.backgroundColor = [UIColor blackColor];
    
    [self addSubview:middleView];
    
    //MARK: - 左边lable
    UILabel * leftLabel = [[UILabel alloc]init];
    self.leftLabel = leftLabel;
    self.leftLabel.text = @"就诊条件";
    self.leftLabel.font = [UIFont systemFontOfSize:25];
    self.leftLabel.textColor = [UIColor lightGrayColor];
//    self.leftLabel.backgroundColor = [UIColor redColor];
    
    self.leftLabel.userInteractionEnabled = YES;
    
    [self addSubview:leftLabel];
    //MARK: - 左边添加手势
    UITapGestureRecognizer * leftRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftTap:)];
    
    [self.leftLabel addGestureRecognizer:leftRecognizer];
    
   
    //MARK: - 1.右边lable
    UILabel * rightLable = [[UILabel alloc]init];
    self.rightLabel = rightLable;
    self.rightLabel.text = @"医生简介";
    self.rightLabel.font = [UIFont systemFontOfSize:25];
    self.rightLabel.textColor = [UIColor lightGrayColor];
//    self.rightLabel.backgroundColor = [UIColor redColor];
    

   
    self.rightLabel.userInteractionEnabled = YES;
    self.rightLabel.multipleTouchEnabled = YES;
    [self addSubview:rightLable];
 
    //MARK: - 2.添加手势
    UITapGestureRecognizer * rightTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    
    [self.rightLabel addGestureRecognizer:rightTap];
    
     //MARK: - 中间的线条
    UIView * lineView = [[UIView alloc]init];
    self.lineView = lineView;
    self.lineView.backgroundColor = XHRColorWithRGB(119, 210, 210) ;
    
    [self addSubview:self.lineView];
    
 }

#pragma mark
#pragma mark -左手势
- (void)leftTap:(UITapGestureRecognizer*)lefTap{
    
    //MARK: - bool值给leftLable做标记
    self.right = NO;
    if (self.changeViewBlock) {
        self.changeViewBlock(self.right,self.leftLabel);
        self.rightLabel.textColor = [UIColor lightGrayColor];
        self.leftLabel.textColor = XHRColorWithRGB(119, 210, 210) ;
    }
    
    self.lineView.transform = CGAffineTransformIdentity;
    
    
}

#pragma mark
#pragma mark - 右手势
- (void)tap:(UITapGestureRecognizer*)tapGesture{
    
    CGFloat leftX = CGRectGetMaxX(self.leftLabel.frame);
    CGFloat rightX = CGRectGetMinX(self.rightLabel.frame);


    self.lineView.transform = CGAffineTransformMakeTranslation(rightX - leftX + self.leftLabel.xhr_Width, 0);

    self.right = YES;
    if (self.changeViewBlock) {
        self.changeViewBlock(self.right,self.rightLabel);
        self.leftLabel.textColor = [UIColor lightGrayColor];
        self.rightLabel.textColor = XHRColorWithRGB(119, 210, 210) ;

    }
    
   }

#pragma mark
#pragma mark - 约束
- (void)setupConstains{

    //MARK: - 中间
    [self.middleView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(2);
//        make.height.equalTo(self.leftLabel.height);
        make.top.bottom.equalTo(self);
        make.centerX.equalTo(self);
//        make.center.equalTo(self);
    }];
    //MARK: - 左边约束
    [self.leftLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.trailing.equalTo(self.middleView.leading).offset(-30);
        
    }];
    
    //MARK: - 右边
    [self.rightLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(self.middleView.trailing).offset(30);
    }];
    
    
    //MARK: - 中间的线条
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(2);
        make.leading.equalTo(self.leftLabel);
        make.trailing.equalTo(self.leftLabel);
        make.bottom.equalTo(0);
    }];
    
}


@end
